package com.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cxt
 * @date 2022/4/13
 * <p>
 * 判断request 是不是来自于手机
 */
public class CheckIsMobileUtil {
    /**
     * @param request 请求
     * @return 是否
     */
    public static boolean checkAgentIsMobile(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent");
        String[] deviceArray = new String[]{"android", "iPhone", "ipod",
                "ipad", "blackberry", "ucweb", "windows phone"};
        if (ua == null) {
            return false;
        }
        ua = ua.toLowerCase();
        for (String string : deviceArray) {
            if (ua.contains(string)) {
                return true;
            }
        }

//        for (String string : deviceArray) {
//            if (ua.indexOf(string) > 0) {
//                return true;
//            }
//        }
        return false;
    }
}
